package com.kedi.usercenter.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 登录后将token存入redis中
 * @author Zyred
 */
public class LoginSaveTokenToRedisUtil {

    private static Logger LOGGER = LoggerFactory.getLogger(LoginSaveTokenToRedisUtil.class);

    private String token;
    private String value;
    private StringRedisTemplate redisTemplate;

    public LoginSaveTokenToRedisUtil(String key, String value, StringRedisTemplate redisTemplate){
        this.token = key;
        this.value = value;
        this.redisTemplate = redisTemplate;
    }

    /**
     * 保存token到redis中
     */
    public void saveTokenToRedis(){

        if(this.token == null)
            LOGGER.error("存入redis中的token为空");

        if(this.value == null)
            LOGGER.error("存入redis中的value为空");

        redisTemplate.opsForValue().set(this.token, this.value);
    }

}
